import type {
  MenuInfoPlain,
  MenuPlainListResp,
  RoleMenuResp,
} from './model/menuModel';

import type { BaseDataResp, BaseIDReq, BaseResp } from '#/api/model/baseModel';

import { requestClient } from '#/api/request';

enum Api {
  CreateMenu = '/sys-api/menu/create',
  DeleteMenu = '/sys-api/menu/delete',
  GetMenuById = '/sys-api/menu/info',
  GetMenuList = '/sys-api/menu/list',
  GetMenuListByRole = '/sys-api/menu/role/list',
  UpdateMenu = '/sys-api/menu/update',
}

/**
 * @description: Get user menu list by role id
 */

export const getMenuListByRole = () => {
  return requestClient.get<BaseDataResp<RoleMenuResp>>(Api.GetMenuListByRole);
};

/**
 * @description: Get menu list
 */

export const getMenuList = (params: any) => {
  return requestClient.get<MenuPlainListResp>(Api.GetMenuList, { params });
};

/**
 *  @description: Create a new menu
 */
export const createMenu = (params: MenuInfoPlain) => {
  return requestClient.post<BaseResp>(Api.CreateMenu, params);
};

/**
 *  @description: Update the menu
 */
export const updateMenu = (params: MenuInfoPlain) => {
  return requestClient.put<BaseResp>(Api.UpdateMenu, params);
};

/**
 *  @description: Delete menus
 */
export const deleteMenu = (id: number) => {
  return requestClient.delete<BaseResp>(`${Api.DeleteMenu}/${id}`);
};

/**
 *  @description: Get menu By ID
 */
export const getMenuById = (id: BaseIDReq) => {
  return requestClient.get<MenuInfoPlain>(`${Api.GetMenuById}/${id}`);
};
